home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / editor / frexxed / fpl / zmacs.fpl < prev    next >
Text File  |  1996-01-02  |  12KB  |  394 lines

  1. // $Id: ZMacs.FPL 1.20 1995/12/31 12:27:42 jskov Exp jskov $
  2. // $VER: ZMacs.FPL 1.11 (01.01.96) © Jesper Skov
  3.  
  4.  
  5. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Ideas ««
  6. // M-y scroll through old yanks (kill ring).
  7. // M-t transpose words
  8.  
  9. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Support routines ««
  10. export int __yankID = GetBufferID("DefaultBlock");  // ID of the block buffer
  11.  
  12. int __killCounter; 
  13. void export emacsBsWord()
  14. {
  15.   int thisBuffer;
  16.   int end_line = ReadInfo("line");
  17.   int end_byte = ReadInfo("byte_position");
  18.   int tempBlock = BlockCreate("__bsTempBlock");
  19.  
  20.   if (ReadInfo("counter")!=(__killCounter+1)){
  21.     killRingInsert();
  22.     Clean("Clear(__yankID);");
  23.   }
  24.   __killCounter = ReadInfo("counter");
  25.  
  26.   CursorLeftWord();
  27.   BlockCut(tempBlock, GetCursor(end_byte, end_line), end_line, GetCursor(end_byte=ReadInfo("byte_position")), end_line=ReadInfo("line"));
  28.  
  29.   thisBuffer = CurrentBuffer(__yankID);
  30.   GotoLine(1);
  31.   BlockPaste(tempBlock);
  32.   CurrentBuffer(thisBuffer);
  33.  
  34.   GotoLine(end_line, end_byte);
  35.  
  36.   Kill(tempBlock);
  37.  
  38.   ringBufferChanged = 1;
  39. }
  40.  
  41. void export emacsDelWord()
  42. {
  43.   int beg_line = ReadInfo("line");
  44.   int beg_byte = ReadInfo("byte_position");
  45.  
  46.   if (ReadInfo("counter")!=(__killCounter+1)){
  47.     killRingInsert();
  48.     Clean("Clear(__yankID);");
  49.   }
  50.   __killCounter = ReadInfo("counter");
  51.  
  52.   CursorRightWord();
  53.   BlockCutAppend(__yankID, GetCursor(ReadInfo("byte_position")), ReadInfo("line"), GetCursor(beg_byte, beg_line), beg_line);
  54.  
  55.   GotoLine(beg_line, beg_byte);
  56.   ringBufferChanged = 1;
  57. }   
  58.  
  59. /*
  60.  * Emacs kill-line embryo.
  61.  * Killed lines will get copied into the block buffer before deleted. Note that
  62.  * the first killed line will first clear the block buffer, and kills following
  63.  * that one will append them to the current one.
  64.  *
  65.  * Paste the buffer with BlockPaste() or BlockPasteRect() just as usual blocks.
  66.  *
  67.  * Coded by Daniel Stenberg
  68.  */
  69.  
  70. void export kill_line()
  71. {
  72.   int this_count = ReadInfo("counter");
  73.   if ((this_count != __killCounter)&&(this_count != __killCounter+1)) {
  74.     // We were not invoked this/last action, clear the buffer
  75.     killRingInsert();
  76.     Clean("Clear(__yankID);");                // Clear the block without any hooks
  77.   }
  78.   ringBufferChanged = 1;
  79.   __killCounter = ReadInfo("counter");
  80.   if(Isnewline(GetChar())) {                // standing on a newline character
  81.     int oldID = GetEntryID();                // get current entry
  82.     Delete();                                // delete the newline character
  83.     CurrentBuffer(__yankID);                // switch to the block buffer
  84.     GotoLine(-1);                            // jump to the bottom
  85.     GotoLine(ReadInfo("line"),ReadInfo("line_length")); // jump to end of line
  86.     Output("\n");                            // add a newline to the buffer
  87.     CurrentBuffer(oldID);                    // switch back to previous buffer
  88.   } else {                                    // delete to end of line
  89.     int curr_col = ReadInfo("column");        // get current column
  90.     int end_col = GetCursor(ReadInfo("line_length")); // get column of the end of line
  91.     int curr_line = ReadInfo("line");        // get line number
  92.  
  93.     BlockCopyAppend(__yankID, end_col, curr_line, curr_col, curr_line);  // append the line to the block
  94.  
  95.     DeleteEol();                            // delete to the end of line
  96.   }
  97. }
  98.  
  99.  
  100. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  101. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Yank History ««
  102. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  103.  
  104. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» misc local variables ««
  105. int maxCount=16;
  106. export int pos[maxCount];
  107. export int size[maxCount];
  108.  
  109. int count=0;
  110. int current=0;
  111.  
  112. export int ringBufferChanged = 0;
  113. //int ringBuffer = New();
  114. int ringBuffer = BlockCreate("yank_history");
  115.  
  116. int prevActivationNo;
  117. int prevX, prevY;
  118.  
  119. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» killRingInsert() ««
  120. // Insertes the Default_block in the yank_history. Call after block copy/cut.
  121. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  122. void export killRingInsert()
  123. {
  124.   if (ReadInfo("size",GetBufferID("DefaultBlock"))&&ringBufferChanged){ // only insert if not empty!
  125.  
  126.     int k=ReadInfo("lines",GetBufferID("DefaultBlock"));
  127.     int i;
  128.     int parent = CurrentBuffer(ringBuffer);
  129.  
  130.     ringBufferChanged = 0;
  131.  
  132.     SetInfo(GetBufferID("DefaultBlock"),"changes",0);
  133.  
  134.     if (count==maxCount){                        // If maxCount reached, delete last entry
  135.       GotoLine(-1);
  136.       CursorUp(size[maxCount-1]);
  137.       DeleteLine(size[maxCount-1]);
  138.     } else 
  139.       count++;
  140.  
  141.     for(i=maxCount-1;i>0;i--){                // scroll array contents
  142.       pos[i]=pos[i-1];
  143.       size[i]=size[i-1];
  144.     }
  145.  
  146.     for(i=1;i<maxCount;i++)                    // adjust start lines according
  147.       pos[i]+=k;                                // to the new block
  148.  
  149.     GotoLine(1);
  150.     BlockPaste(GetBufferID("DefaultBlock"));    // insert block in history
  151.     Output("\n");
  152.  
  153.     pos[0]=1;
  154.     size[0]=k;
  155.  
  156.     CurrentBuffer(parent);
  157.   }
  158. }
  159.  
  160. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» killRingYankNext() ««
  161. // Replaces previous yank with the next entry in the yank_history.
  162. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  163. void export killRingYankNext()
  164. {
  165.   if(!((ReadInfo("counter")==prevActivationNo+1) || ReadInfo("counter")==__yankCounter+1)){
  166.     ReturnStatus("Previous command was not a yank!");
  167.     return;
  168.   }
  169.   prevActivationNo = ReadInfo("counter");
  170.  
  171.   if(ReadInfo("counter")==__yankCounter+1)
  172.     current=0;
  173.  
  174.   BlockDelete(0,prevX, prevY, ReadInfo("column"), ReadInfo("line"));
  175.  
  176.   current++;
  177.   if(current==count)                        // wrap!
  178.     current=0;
  179.  
  180.   prevX = ReadInfo("column");
  181.   prevY = ReadInfo("line");
  182.  
  183.   {
  184.   int parent = CurrentBuffer(ringBuffer);
  185.   int tempBlock = BlockCreate("_yankScroll");
  186.  
  187.   GotoLine(pos[current]+size[current]);
  188.   CursorLeft();                                // adjust the extra return!
  189.   BlockMark(2,0,pos[current],ReadInfo("column"),ReadInfo("line"));
  190.   BlockCopy(tempBlock,0,pos[current],ReadInfo("column"),ReadInfo("line"));
  191.  
  192.   CurrentBuffer(parent);
  193.   BlockPaste(tempBlock);
  194.   Kill(tempBlock);
  195.   }
  196. }
  197.  
  198. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» killRingYank() ««
  199. int __yankCounter;
  200.  
  201. void export killRingYank()
  202. {
  203.   prevX = ReadInfo("column");                // remember position - kryNext may need it
  204.   prevY = ReadInfo("line");
  205.  
  206.   killRingInsert();
  207.  
  208.   __yankCounter = ReadInfo("counter");
  209.   BlockPaste();                                // insert block
  210. }
  211.  
  212. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  213. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  214.  
  215.  
  216. void export emacsOpenFile(int viewControl)
  217. {
  218.   int old_popup = ReadInfo("popup_view");
  219.   SetInfo(0,"popup_view",viewControl);
  220.   Open("");
  221.   SetInfo(0,"popup_view",old_popup);
  222. }
  223.  
  224.  
  225. void export emacsIncludeFile()
  226. {
  227.   int old_popup = ReadInfo("popup_view");
  228.   SetInfo(0,"popup_view",0);
  229.   InsertFile("");
  230.   SetInfo(0,"popup_view",old_popup);
  231. }
  232.  
  233.  
  234.  
  235. void export emacsGotoBuffer(int viewControl)
  236. {
  237.   int id=PromptBuffer("",1);
  238.   if (id){
  239.     Activate(id,viewControl);
  240.     CurrentBuffer(id);
  241.   }
  242. }
  243.  
  244.  
  245. void export emacsTranspose()
  246. {
  247.   int letter=GetChar();
  248.  
  249.   if (Isnewline(letter)){
  250.     CursorLeft();
  251.     letter=GetChar();
  252.     Delete();
  253.     CursorLeft();
  254.     Output(itoc(letter));
  255.     CursorRight();
  256.   } else {
  257.     Delete();
  258.     CursorLeft();
  259.     Output(itoc(letter));
  260.     if (Isnewline(GetChar())){                // Fix if moved to prev line
  261.       CursorRight();
  262.     }
  263.   }
  264. }
  265.  
  266. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Configuration ««
  267.  
  268. string metaKey = "amiga";                            // Default/0
  269.  
  270. ConstructInfo("emacs_meta","","","GCW(system)","Amiga|Escape|Alt",0,0);
  271.  
  272. if (ReadInfo("emacs_meta")==1){
  273.   metaKey = "'esc'";                                // 1=Esc
  274. } else if (ReadInfo("emacs_meta")==2){
  275.   metaKey = "alt";                                    // 2=alt
  276. }
  277.  
  278. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Cursor movement ««
  279. AssignKey("CursorLeft();",    "control b");
  280. AssignKey("CursorRight();",    "control f");
  281. AssignKey("CursorLeftWord();", metaKey+" b");
  282. AssignKey("CursorRightWord();",metaKey+" f");
  283.  
  284. AssignKey("CursorDown();",    "control n");
  285. AssignKey("CursorUp();",    "control p");
  286.  
  287. AssignKey("PageUp();",        "control V");
  288. AssignKey("PageUp();",        metaKey+" v");
  289. AssignKey("PageDown();",    "control v");
  290. AssignKey("GotoLine(ReadInfo(\"line\"));","control a");
  291. AssignKey("GotoLine(ReadInfo(\"line\"),ReadInfo(\"line_length\"));","control e");
  292. AssignKey("                                // Next view
  293. {
  294.   int id=PrevView();
  295.  
  296.   Activate(id, 0);CurrentBuffer(id);
  297. }",                            "control x o");
  298. AssignKey("                                // Previous view
  299. {
  300.   int id=NextView();
  301.  
  302.   Activate(id, 0);CurrentBuffer(id);
  303. }",                            "control x O");
  304. AssignKey("GotoLine();",    "control c g");
  305. AssignKey("GotoLine(1,0);",    metaKey+" <");
  306. AssignKey("Bottom();End();",metaKey+" >");
  307.  
  308. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Editing ««
  309. AssignKey("kill_line();",    "control k");
  310. AssignKey("DeleteEol();",    "shift 'Del'");
  311. AssignKey("Backspace(ReadInfo(\"byte_position\"));","shift 'backspace'");
  312. AssignKey("
  313. {
  314.   if (ReadInfo(\"line_length\")==1){
  315.     kill_line();                         // Don't overdo it if the line is
  316.   } else {                                 // is empty
  317.     GotoLine(ReadInfo(\"line\"));kill_line();kill_line();
  318.   }
  319. }",                            "control K");
  320.  
  321. AssignKey("Delete();",        "control d");
  322. AssignKey("emacsDelWord();",    metaKey+" d");
  323. AssignKey("emacsBsWord();",metaKey+" 'backspace'");
  324.  
  325. AssignKey("Undo();",        "control x u");
  326.  
  327. AssignKey("CenterLine(0);", metaKey+" s", "!block_exist");
  328. AssignKey("CenterBlock();", metaKey+" s", "block_exist");
  329.  
  330. AssignKey("emacsTranspose();","control t");
  331.  
  332. AssignKey("fillText();",metaKey+" q");
  333.  
  334. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Block control ««
  335. AssignKey("BlockMark();",    "control 'space'");
  336. AssignKey("killRingInsert();BlockCopy();ringBufferChanged=1;",    "control W");
  337. AssignKey("killRingInsert();BlockCopy();ringBufferChanged=1;",    metaKey+" w");
  338. AssignKey("killRingInsert();BlockCut();ringBufferChanged=1;",    "control w");
  339. AssignKey("killRingYankNext();",metaKey+" y");
  340. AssignKey("killRingYank();",    "control y");
  341.  
  342. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Macro control ««
  343. AssignKey("if (!ReadInfo(\"macro_on\"))
  344.              {MacroRecord(1);};","control x (");
  345. AssignKey("if (ReadInfo(\"macro_on\")){MacroRecord(1,\"\",\"control x e\");};","control x )");
  346.  
  347.  
  348. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Buffer control ««
  349. AssignKey("SaveChanges();",    "control x control s");
  350. AssignKey("SaveAs();",        "control x control w");
  351. AssignKey("emacsOpenFile(0);","control x control f");
  352. AssignKey("emacsOpenFile(1);","control x 4 f");
  353. AssignKey("emacsIncludeFile();","control x i");
  354. AssignKey("Kill(GetBufferID());","control x k");
  355. AssignKey("QuitAll();",        "control x control c");
  356. AssignKey("emacsGotoBuffer(0);","control x b");
  357. AssignKey("emacsGotoBuffer(1);","control x 4 b");
  358.  
  359. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» View control ««
  360. AssignKey("MaximizeView();","control x 1");
  361. AssignKey("RemoveView();",    "control x 0");
  362. AssignKey("CurrentBuffer(Activate(DuplicateEntry(),1));","control x 2");
  363. AssignKey("CenterView();",    "control l");
  364.  
  365. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Folder control ««
  366. AssignKey("FoldShow();", "control c control s");     // SHOW
  367. AssignKey("FoldShow(0);", "control c control S e");  // (e)xclusive
  368. AssignKey("FoldShow(-1);", "control c control S a"); // (a)ll
  369. AssignKey("FoldDelete();", "control c control S d"); // (d)elete
  370. AssignKey("FoldHide();", "control c control h");     // HIDE
  371. AssignKey("FoldHide(0);", "control c control H e");  // (e)xclusive
  372. AssignKey("FoldHide(-1);", "control c control H a"); // (a)ll
  373. AssignKey("Fold();", "control c control H n");       // (n)ew
  374.  
  375. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Search & Replace ««
  376. AssignKey("{ int ret; if ((ret=ReplaceSet())>=0)
  377.     { if (Replace()<0) DisplayBeep(); }
  378.          else ReturnStatus(GetReturnMsg(ret)); };", metaKey+" shift 5");
  379.  
  380. AssignKey("MySearch(0);", "control S");        // Repeat search forwards
  381. AssignKey("MySearch(1);", "control R");        // do backwards
  382.  
  383. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Miscellaneous ««
  384. AssignKey("SetInfo(-1,\"wall_right\",ReadInfo(\"column\"));","control x f");
  385.                                                 // Set wall_right
  386.  
  387. AssignKey("checkWord();",metaKey+" shift 4"); // ISpell
  388.  
  389. AssignKey("string path = PromptFile(\"\",\"DirED path\",\"\",\"d\");if(strlen(path)) dired(path);","control x d");
  390.  
  391. AssignKey("Prompt();",        metaKey+" x");
  392.  
  393. AssignKey("Iconify();",        "control z");
  394.